# app/models/models.py

from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime, func
from sqlalchemy.orm import relationship
from app.db.base import Base

# 内部系统使用的表
class InternalUser(Base):
    __tablename__ = 'internal_users'

    name_id = Column(String(255), primary_key=True, comment='用户ID')
    internal_videos = relationship("InternalVideo", back_populates="user")
    internal_voices = relationship("InternalVoice", back_populates="user")
    internal_jobs = relationship("InternalJob", back_populates="user")

class InternalVideo(Base):
    __tablename__ = 'internal_videos'

    id = Column(Integer, primary_key=True, index=True, comment='主键递增')
    name_id = Column(String(255), ForeignKey('internal_users.name_id'), nullable=False, comment='用户ID')
    video_url = Column(String(500), nullable=False, comment='视频链接')
    title = Column(String(255), nullable=False, comment='标题')
    job_id = Column(String(50), nullable=False, unique=True, comment='随机生成的job_id')  # 随机生成的job_id
    user = relationship("InternalUser", back_populates="internal_videos")
    task_finished = Column(Boolean, default=False, comment='任务是否完成(true/false)用户在回调时更新')
    create_time = Column(DateTime, default=func.now(), comment='创建时间')

class InternalVoice(Base):
    __tablename__ = 'internal_voices'

    id = Column(Integer, primary_key=True, index=True, comment='主键递增')
    name_id = Column(String(255), ForeignKey('internal_users.name_id'), nullable=False, comment='用户ID')
    voice_id = Column(String(255), nullable=True, unique=True, comment='微服务（禅镜）返回的声音ID')
    title = Column(String(255), nullable=False, comment='标题')
    audio_url = Column(String(500), nullable=False, comment='音频链接')
    user = relationship("InternalUser", back_populates="internal_voices")
    task_finished = Column(Boolean, default=False, comment='任务是否完成(true/false)用户在回调时更新')
    job_id = Column(Integer, nullable=False, unique=True, comment='微服务返回的job_id')  # 随机生成的job_id
    create_time = Column(DateTime, default=func.now(), comment='创建时间')

class InternalJob(Base):
    __tablename__ = 'internal_jobs'

    id = Column(Integer, primary_key=True, index=True, comment='主键递增')
    name_id = Column(String(255), ForeignKey('internal_users.name_id'), index=True, nullable=False, comment='用户ID')
    job_id = Column(Integer, nullable=False, unique=True, comment='随机生成的job_id')
    video_url = Column(String(500), nullable=True, comment='存储创作视频链接')  # 存储创作视频链接
    personUrl = Column(String(500), nullable=True, comment='存储数字人链接')  # 存储数字人链接
    audio_url = Column(String(500), nullable=True, comment='存储音频链接')  # 存储音频链接
    voice_id = Column(String(255), nullable=True, comment='语音ID')  # 语音ID
    text = Column(String(10000), nullable=True, comment='文本内容')  # 文本内容
    title = Column(String(255), nullable=True, comment='标题')  # 标题
    only_generate_audio = Column(Boolean, default=False, comment='是否只生成音频')  # 是否只生成音频
    user = relationship("InternalUser", back_populates="internal_jobs")
    task_finished = Column(Boolean, default=False, comment='任务是否完成(true/false)用户在回调时更新')
    create_time = Column(DateTime, default=func.now(), comment='创建时间')